﻿<?php
require_once '../../public/inc/DB.php';
$db = new DB('jusmor_user');

$action = $_POST['action'];

if($action == 'login') {
	$user_name = $_POST['user_name'];
	$password = $_POST['password'];
	
	if(empty($user_name) || empty($password)) {
		echo '登录失败！3秒后跳转到登录页面……<script>setTimeout(function () {window.location.href="/jusmor_admin/index.php"; }, 3000);</script>';
		exit();
	}
	$condition = array('user_name'=>$user_name, 'password'=>md5($password));
	$res = $db->fetchCount($condition);
	if(empty($res)) {
		echo '登录失败！3秒后跳转到登录页面……<script>setTimeout(function () {window.location.href="/jusmor_admin/index.php"; }, 3000);</script>';
		exit();
	}
	
	setcookie('jusmor_user_name', $user_name, time()+60*60*5, '/jusmor_admin');
	setcookie('jusmor_isLogin', '1', time()+60*60*5, '/jusmor_admin');
	
	echo '登录成功！3秒后跳转到后台主页……<script>setTimeout(function () {window.location.href="/jusmor_admin/main.php"; }, 3000);</script>';
	exit();
}